package jogs.client;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import java.awt.Color;
import java.awt.Font;

public class ListRenderer extends JLabel implements ListCellRenderer
{

	public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focus)
	{
		setText(value.toString());
		setOpaque(true);
		try
		{
			ListObject lo = (ListObject)value;
			switch(lo.getType())
			{
				case 0:
					isRoom(selected);
					break;
				case 1:
					isUser(selected);
					break;
			}
		}
		catch(ClassCastException ce){}
		
		return this;
	}
	
	private void isRoom(boolean selected)
	{
		if(selected)
		{
			this.setBackground(Color.BLUE);
			//this.setForeground(Color.RED);
			//this.setFont(new Font(null, Font.BOLD, 12));
		}
		else
		{
			this.setBackground(Color.WHITE);
		}
		this.setForeground(Color.RED);
		this.setFont(new Font(null, Font.BOLD, 12));
	}
	
	private void isUser(boolean selected)
	{
		if(selected)
		{
			this.setBackground(Color.BLUE);
			this.setForeground(Color.WHITE);
		}
		else
		{
			this.setBackground(Color.WHITE);
			this.setForeground(Color.BLACK);
		}
		this.setFont(new Font("SansSerif", Font.PLAIN, 12));
	}

}
